﻿Imports System
Imports System.Globalization
Imports System.Reflection

Namespace System.Workflow.Activities.Rules
    Friend MustInherit Class BaseMethodInfo
        Inherits MethodInfo
        ' Methods
        Public Sub New(ByVal method As MethodInfo)
            Me.actualMethod = method
            Me.resultType = method.ReturnType
            Me.expectedParameters = method.GetParameters
        End Sub

        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            Dim info As BaseMethodInfo = [TryCast](obj,BaseMethodInfo)
            If (((info Is Nothing) OrElse (Not Me.actualMethod Is info.actualMethod)) OrElse ((Not Me.resultType Is info.resultType) OrElse (Me.expectedParameters.Length <> info.expectedParameters.Length))) Then
                Return False
            End If
            Dim i As Integer
            For i = 0 To Me.expectedParameters.Length - 1
                If (Not Me.expectedParameters(i).ParameterType Is info.expectedParameters(i).ParameterType) Then
                    Return False
                End If
            Next i
            Return True
        End Function

        Public Overrides Function GetBaseDefinition() As MethodInfo
            Return Me.actualMethod.GetBaseDefinition
        End Function

        Public Overrides Function GetCustomAttributes(ByVal inherit As Boolean) As Object()
            Return Me.actualMethod.GetCustomAttributes(inherit)
        End Function

        Public Overrides Function GetCustomAttributes(ByVal attributeType As Type, ByVal inherit As Boolean) As Object()
            Return Me.actualMethod.GetCustomAttributes(attributeType, inherit)
        End Function

        Public Overrides Function GetHashCode() As Integer
            Dim num As Integer = (Me.actualMethod.GetHashCode Xor Me.resultType.GetHashCode)
            Dim i As Integer
            For i = 0 To Me.expectedParameters.Length - 1
                num = (num Xor Me.expectedParameters(i).GetHashCode)
            Next i
            Return num
        End Function

        Public Overrides Function GetMethodImplementationFlags() As MethodImplAttributes
            Return Me.actualMethod.GetMethodImplementationFlags
        End Function

        Public Overrides Function GetParameters() As ParameterInfo()
            Return Me.expectedParameters
        End Function

        Public Overrides Function Invoke(ByVal obj As Object, ByVal invokeAttr As BindingFlags, ByVal binder As Binder, ByVal parameters As Object(), ByVal culture As CultureInfo) As Object
            Throw New NotImplementedException
        End Function

        Public Overrides Function IsDefined(ByVal attributeType As Type, ByVal inherit As Boolean) As Boolean
            Return Me.actualMethod.IsDefined(attributeType, inherit)
        End Function


        ' Properties
        Public Overrides ReadOnly Property Attributes As MethodAttributes
            Get
                Return (Me.actualMethod.Attributes And Not MethodAttributes.Static)
            End Get
        End Property

        Public Overrides ReadOnly Property DeclaringType As Type
            Get
                Return Me.actualMethod.DeclaringType
            End Get
        End Property

        Public Overrides ReadOnly Property MethodHandle As RuntimeMethodHandle
            Get
                Return Me.actualMethod.MethodHandle
            End Get
        End Property

        Public Overrides ReadOnly Property Name As String
            Get
                Return Me.actualMethod.Name
            End Get
        End Property

        Public Overrides ReadOnly Property ReflectedType As Type
            Get
                Return Me.actualMethod.ReflectedType
            End Get
        End Property

        Public Overrides ReadOnly Property ReturnType As Type
            Get
                Return Me.resultType
            End Get
        End Property

        Public Overrides ReadOnly Property ReturnTypeCustomAttributes As ICustomAttributeProvider
            Get
                Return Me.actualMethod.ReturnTypeCustomAttributes
            End Get
        End Property


        ' Fields
        Protected actualMethod As MethodInfo
        Protected expectedParameters As ParameterInfo()
        Protected resultType As Type
    End Class
End Namespace

